﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (User.Identity.IsAuthenticated)
            {
                lblRoleTest.Text = User.IsInRole("ADMIN") ? "ADMIN" : "FAILED";
                lblProfile.Text = Profile.Facility;

                SecurityAgent.ObjectClaim[] objs = SecurityAgent.ObjectSecurity.Client.ObjectSecurityAgent.GetClaims();
                listObjects.DataSource = objs;
                listObjects.DataBind();

                TestResourceServiceReference.Service1Client client = new TestResourceServiceReference.Service1Client();

                try
                {
                    string ret1 = client.ReadSalesOrder(SecurityAgent.ObjectSecurity.Client.ObjectSecurityAgent.CurrentUserToken, "ORDER1");
                    lblTestService1.Text = "Succeeded";
                }
                catch (Exception ex1)
                {
                    lblTestService1.Text = ex1.Message;
                }

                try
                {
                    string ret1 = client.ReadSalesOrder(SecurityAgent.ObjectSecurity.Client.ObjectSecurityAgent.CurrentUserToken, "ORDER2");
                    lblTestService2.Text = "Undefined Object Went Through";
                }
                catch (Exception ex2)
                {
                    lblTestService2.Text = ex2.Message;
                }

            }
            else
            {
                Response.Redirect("Account/Login.aspx");
            }
        }
    }
}
